<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
		<title>信息编辑</title>
		<link href="css/bootstrap.min.css" rel="stylesheet">
		<link href="css/materialdesignicons.min.css" rel="stylesheet">
		<link href="css/style.css" rel="stylesheet">
		<script type="text/javascript" src="js/jquery.min.js"></script>
		<script type="text/javascript" src="js/bootstrap.min.js"></script>
		<!--图表插件-->
		<link rel="stylesheet" type="text/css" href="layui/layui/css/layui.css">
		<script type="text/javascript" src="layui/layui/layui.js"></script>
		<script type="text/javascript" src="js/Chart.js"></script>
		<script src="https://cdn.jsdelivr.net/npm/js-cookie@2/src/js.cookie.min.js"></script>
		<script src="js/ServerUrl.js"></script>
		<script type="text/javascript">
			$(function() {
				// 	console.log(storage.getItem("username"));
				if (Cookies.get('islogin')) {
					$("#id").attr("value", Cookies.get('id'));
					$("#identity").attr("value", Cookies.get('identity'));
					$("#username").attr("value", Cookies.get('username'));
					$("#phone").attr("value", Cookies.get('phone'));
					// console.log(Cookies.get('username'));
					// console.log(Cookies.get('phone'));
					// console.log(Cookies.get('identity'));
				}
			});

			function submitProfile() {
				var id = $("#id").val();
				var username = $("#username").val();
				var phone = $("#phone").val();
				$.ajax({
					//几个参数需要注意一下
					type: "post", //方法类型
					dataType: "json", //预期服务器返回的数据类型
					url: serverUrl + "/submitProfile",
					data: {
						"id": id,
						"username": username,
						"phone": phone
					},
					success: function(result) {
						// console.log(result);
						if (result.status == 200) {
							layer.msg('修改成功');
							if (Cookies.get('islogin') == "true" && Cookies.get('expires') == "3") {
								Cookies.set('username', username, {
									expires: 3
								});
								Cookies.set('phone', phone, {
									expires: 3
								});
							} else if (Cookies.get('islogin') == "true" && Cookies.get('expires') == "temp") {
								Cookies.set('username', username);
								Cookies.set('phone', phone);
							}
						} else if (result.status == 404) {
							layer.msg('修改失败');
						}
					},
					error: function() {
						layer.msg('提交修改时异常');
					}
				});
			}
		</script>
	</head>
	<body>
		<!--页面主要内容-->

		<div class="container-fluid">

			<div class="row">
				<div class="col-lg-12">
					<div class="card">
						<div class="card-body">
							<h3>编辑个人信息</h3>
							<hr>
							<form action="#!" method="post" onsubmit="return false" class="site-form">
								<div class="form-group">
									<label for="userid">用户id</label>
									<input type="text" class="form-control" name="id" id="id" value=""
										disabled="disabled" readonly="readonly" />
								</div>
								<div class="form-group">
									<label for="userid">我的权限</label>
									<input type="text" class="form-control" name="identity" id="identity" value=""
										disabled="disabled" readonly="readonly" />
								</div>

								<div class="form-group">
									<label for="username">用户名</label>
									<input type="text" class="form-control" name="username" id="username" value="" />
								</div>
								<div class="form-group">
									<label for="username">电话</label>
									<input type="text" class="form-control" name="phone" id="phone" value="" />
								</div>
								<br />
								<button onclick="submitProfile()" class="btn btn-lg btn-primary">提交保存</button>
							</form>

						</div>
					</div>
				</div>

			</div>

		</div>
		<!--End 页面主要内容-->
	</body>
</html>
